function native() {
    AndroidWebView.intopay();
}
//跳转ios原生
function nativeIos(a) {
    gotoGroupBuyPayChooseWindow();
}
var detailObj = {
    lGroupBuyId: "",
    userid: "",
    init: function() {
        this.userid = $.cookie('userid');
        this.lGroupBuyId = this.getUrlData("lGroupBuyId");
        this.getGoodsDetail();
        this.wxJoinNow();
        this.appJoinNow();
    },
    getGoodsDetail: function() {
        var me = this;
        var url = magic_config.urlPrefix + 'GroupbuyService/getgroupbuyinfo';
        var data = {
            lGroupBuyId: me.lGroupBuyId
        }
        console.log(data);
        $.ajax({
            url: url,
            type: 'get',
            data: data,
            //async: false,
            dataType: 'json',
            success: function(res) {
                var nCode = res.return.nCode;
                if (nCode === 0) {
                    console.log(res.response);
                    me.splitDetail(res.response.cdoData);
                } else {
                    console.log("数据请求失败，后到前");
                }
            },
            error: function(res) {
                console.log("数据请求失败，前到后");
            }
        });
    },
    splitDetail: function(goodsDetail) {
        //商品名字
        $(".goodsname").html('<span class="dislogo">拼团价</span>&nbsp&nbsp' + goodsDetail.sName);
        //商品价格
        $(".goodspric").html('<span>¥</span>' + goodsDetail.nGroupPrice);
        $(".oprice").html("¥" + goodsDetail.nMainPrice);
        $(".pnum").html('<span>' + goodsDetail.nSaleStock + '</span>人参与');
        //进度条
        var barStr = parseInt((goodsDetail.nSaleStock / goodsDetail.nTotalStock) * 100) + "%";
        console.log(barStr);
        $(".bartxt").html('已抢' + barStr)
        $(".progress").width(barStr);
        if(goodsDetail.nSaleStock >=goodsDetail.nTotalStock){
            $(".invtefirend").hide();
            $(".gameover").show();
        }else{
            $(".invtefirend").show();
            $(".gameover").hide();
        }
        //倒计时
        this.getActiveEndTime(goodsDetail.dEndTime);
        // //插入图片详情
        var imgDetailStr = '';
        for (var i = 0; i < goodsDetail.sPictures.length; i++) {
            imgDetailStr += ' <div class="imgbox"><img src="' + goodsDetail.sPictures[i] + '" alt=""></div>';
        }
        $(".imgbox").html(imgDetailStr);
        //顶部轮播
        var bannerStr = '';
        for (var i = 0; i < goodsDetail.sPictures.length; i++) {
            bannerStr += '<div class="swiper-slide"><div class="img_box2"><img src="' + goodsDetail.sPictures[i] + '" ></div></div>';
        }
        $(".swiper-wrapper").html(bannerStr);
        this.swiper();

    },
    //轮播图
    swiper: function() {
        var swiper = new Swiper('.swiper-container', {
            autoplay: true,
            autoplay: {
                speed: 1000,
                disableOnInteraction: false,
            },
            loop: true,
            centeredSlides: true,
            pagination: {
                el: '.swiper-pagination',
            },
        });
    },
    //倒计时
    getActiveEndTime: function(endTimeStr) {
        var me = this;
        var interval = setInterval(function() {
            var str = '';
            var endTime = (new Date(endTimeStr)).getTime();
            var date = new Date();
            var nowTime = date.getTime();
            endTime = parseInt(endTime / 1000);
            countdownTime = endTime - parseInt(nowTime / 1000);
            var day;
            var hour;
            var min;
            var sec;
            day = parseInt(countdownTime / (3600 * 24));
            hour = parseInt((countdownTime - day * (3600 * 24)) / 3600);
            min = parseInt((countdownTime - day * (3600 * 24) - hour * 3600) / 60);
            sec = countdownTime - day * (3600 * 24) - hour * 3600 - min * 60;
            if (Number(sec) < 10) {
                sec = "0" + sec;
            }
            if (Number(min) < 10) {
                min = "0" + min;
            }
            if (Number(hour) < 10) {
                hour = "0" + hour;
            }
            var a = '<span class="c-size">' + day + '</span>天<span class="c-size">' + hour + '</span>时<span class="c-size">' + min + '</span>分<span class="c-size">' + sec + '秒</span>';
            $(".end").html('距离结束' + a);

        }, 1000);
    },
    //微信环境下点击立即参团
    wxJoinNow: function() {
        var me = this;
        $(".wx_joinnow").bind("click", function() {

            if (me.userid == null) {
                $(".layerbox").show();
                $(".normallogin").show();
            } else {

            }

        })
    },
    //app环境下点击立即参团
    appJoinNow: function() {
        $(".invtefirend").bind("click", function() {
            //跳转原生页面
            var u = navigator.userAgent;
            if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
                native();
            } else if (u.indexOf('iPhone') > -1) {
                //苹果手机
                nativeIos()
            }
        })
    },
        //获得链接参数
    getUrlData: function(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    },
}
detailObj.init();